{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "import paddle\n",
    "from paddle.nn import Linear\n",
    "import paddle.nn.functional as F\n",
    "import os\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "train_dataset=paddle.vision.datasets.MNIST(mode='train')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 432x288 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAJIAAACcCAYAAACUcfL+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvIxREBQAACmJJREFUeJztnW2MVNUZx39/FnYF5bWLDayENawSaROBrLWGRhHkRVMkfGiCGKjEpqQBsSkEoSSFNCa12rQJL0lrLaFKpbEoKo0NAQMfiC1hNxBcCitgAbe8hyIWmwr09MNctvfcwu7szJk7MzvPL5nM+d9z595ndv8597n33HmunHMYRr70KHYARvfAjGQEwYxkBMGMZATBjGQEwYxkBKGijSTpgKTxxY6jOyC7jmSEoKJHJCMcFW0kScckPSJppaQ/SNog6TNJH0q6W9IySWclfSJpcuxzcyUdjNb9WNK8xHaXSDol6aSk70hykhqivhpJP5N0QtIZSb+U1Dvt7x6aijZSgmnAa8BAYC+wlczfpw74MfCr2LpngW8C/YC5wC8kjQWQNBX4AfAI0AA8lNjPT4G7gdFRfx3wo4J8ozRxzlXsCzhG5h++EtgWWz4N+CdQFem+gAMG3GQ7bwPPRu11wE9ifQ3RZxsAAZeBEbH+B4C/Fftvke+rZwpeLRfOxNr/As47567F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xZ4unp06d7uhyuE3VGNhckxwGzgQ8l7YuW/ZCMgd6IyiWfAL5VmBCNciCbs7ZdwM0qQVmJZAOwK9tGILrNXNuFCxc8nXxM1r59+zydLOXXVcaNG9feTv7Wf8qUKZ7u3bt3XvsqB2xEMoJgRjKCYEYyglBWOdLu3bvb2y+++KLXl7wvuq2tLa999enTx9PJx7fH58eSj2evRGxEMoJgRjKCUFaHts2bN9+wnQ3Jn/hMmzbN01VVVZ5evHixp5PV/Q0fG5GMIJiRjCCYkYwgWFkbo0OsrI2RKmYkIwhmJCMIZiQjCGYkIwhmJCMIZiQjCGYkIwhmJCMIZiQjCGYkIwipzrVJOgccB2qB86ntuGuUamzFimu4c67Tog2pGql9p1JTNhOBxaBUYyvVuK5jhzYjCGYkIwjFMtLLRdpvNpRqbKUaF1CkHMnoftihzQhCqkaSNFVSq6QjkopaTlnSOklnJbXElpVE7fByrG2empEkVQFrgUeBUcATUb3uYrEemJpYViq1w8uvtrlzLpUX8ACwNaaXAcvS2v9NYqoHWmK6FRgStYcArcWMLxbXO8CkUo3POZfqoa0O+CSm26JlpUTJ1Q4vl9rmaRrpRnUo7ZSxA3KtbV4M0jRSGzAspu8ATqa4/2zIqnZ4GuRT27wYpGmkPcBdku6UVA3MJFOru5S4Xjscilg7PIva5lBqtc1TThofAz4CjgLLi5zAbiTzsJ4rZEbLp4EvkTkbOhy9DypSbN8gc9jfD+yLXo+VSnw3etmVbSMIdmXbCIIZyQiCGckIghnJCIIZyQiCGckIghnJCIIZyQjCfwGaN0JV33lHywAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 144x144 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "图像数据形状和对应数据为: (28, 28)\n",
      "图像标签形状和对应数据为: (1,) [5]\n",
      "\n",
      "输出第一个批次的第一个图像，对应标签数字为[5]\n"
     ]
    }
   ],
   "source": [
    "train_data0=np.array(train_dataset[0][0])\n",
    "train_label_0=np.array(train_dataset[0][1])\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "plt.figure(\"Image\")\n",
    "plt.figure(figsize=(2,2))\n",
    "plt.imshow(train_data0,cmap=plt.cm.binary)\n",
    "plt.axis('on')\n",
    "plt.title('image')\n",
    "plt.show()\n",
    "print(\"图像数据形状和对应数据为:\",train_data0.shape)\n",
    "print(\"图像标签形状和对应数据为:\",train_label_0.shape,train_label_0)\n",
    "print(\"\\n输出第一个批次的第一个图像，对应标签数字为{}\".format(train_label_0))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [],
   "source": [
    "class MNIST(paddle.nn.Layer):\n",
    "    def __init__(self):\n",
    "        super(MNIST,self).__init__()\n",
    "        self.fc1=Linear(in_features=784,out_features=100)\n",
    "        self.fc2=Linear(in_features=100,out_features=100)\n",
    "        self.fc3=Linear(in_features=100,out_features=10)\n",
    "    def forward(self,inputs):\n",
    "        outputs1=self.fc1(inputs)\n",
    "        outputs1=F.relu(outputs1)\n",
    "        outputs2=self.fc2(outputs1)\n",
    "        outputs2=F.relu(outputs2)\n",
    "        outputs_final=self.fc3(outputs2)\n",
    "        outputs_final=F.softmax(outputs_final)\n",
    "        return outputs_final  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [],
   "source": [
    "def norm_img(img):\n",
    "    assert len(img.shape)==3\n",
    "    batch_size,img_h,img_w=img.shape[0],img.shape[1],img.shape[2]\n",
    "    img=img/255\n",
    "    img=paddle.reshape(img,[batch_size,img_h*img_w])\n",
    "    return img"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "epoch_id:0,batch_id:0,loss is:[2.3146117]\n",
      "epoch_id:0,batch_id:1000,loss is:[2.2435918]\n",
      "epoch_id:0,batch_id:2000,loss is:[1.8442358]\n",
      "epoch_id:0,batch_id:3000,loss is:[1.7105687]\n",
      "epoch_id:1,batch_id:0,loss is:[1.5987104]\n",
      "epoch_id:1,batch_id:1000,loss is:[1.5856738]\n",
      "epoch_id:1,batch_id:2000,loss is:[1.7624445]\n",
      "epoch_id:1,batch_id:3000,loss is:[1.589218]\n",
      "epoch_id:2,batch_id:0,loss is:[1.530166]\n",
      "epoch_id:2,batch_id:1000,loss is:[1.526788]\n",
      "epoch_id:2,batch_id:2000,loss is:[1.5132663]\n",
      "epoch_id:2,batch_id:3000,loss is:[1.4826579]\n",
      "epoch_id:3,batch_id:0,loss is:[1.6083496]\n",
      "epoch_id:3,batch_id:1000,loss is:[1.6301045]\n",
      "epoch_id:3,batch_id:2000,loss is:[1.6229111]\n",
      "epoch_id:3,batch_id:3000,loss is:[1.583476]\n",
      "epoch_id:4,batch_id:0,loss is:[1.5871838]\n",
      "epoch_id:4,batch_id:1000,loss is:[1.6026115]\n",
      "epoch_id:4,batch_id:2000,loss is:[1.6564803]\n",
      "epoch_id:4,batch_id:3000,loss is:[1.5225061]\n"
     ]
    }
   ],
   "source": [
    "import paddle\n",
    "paddle.vision.set_image_backend('cv2')\n",
    "model=MNIST()\n",
    "def train(model):\n",
    "    model.train()\n",
    "    train_loader=paddle.io.DataLoader(paddle.vision.datasets.MNIST(mode='train'),batch_size=16,shuffle=True)\n",
    "    opt=paddle.optimizer.SGD(learning_rate=1e-2,parameters=model.parameters())\n",
    "    EPOCH_NUM=5\n",
    "    for epoch in range(EPOCH_NUM):\n",
    "        for batch_id,data in enumerate(train_loader()):\n",
    "            images=norm_img(data[0]).astype('float32')\n",
    "            labels=data[1].astype('int64')\n",
    "            predicts=model(images)\n",
    "            loss=F.cross_entropy(predicts,labels)\n",
    "            avg_loss=paddle.mean(loss)\n",
    "            if batch_id%1000==0:\n",
    "                print(\"epoch_id:{},batch_id:{},loss is:{}\".format(epoch,batch_id,avg_loss.numpy()))\n",
    "            avg_loss.backward()\n",
    "            opt.step()\n",
    "            opt.clear_grad()\n",
    "train(model)\n",
    "paddle.save(model.state_dict(),'./mnist.pdparams')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAVEAAAD8CAYAAADOg5fGAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvIxREBQAAHBJJREFUeJzt3XmUVPWd9/H3t5teaLZmaRabpUFAIS6IHUURVAwhmkUzo4nRGTkZ82ASx8fEeSbqyXkm25wczUyMJzOODo/6DGbGLU6MPGiCyJKOC0sDiqyCinazNluz9Ub37/mjbhfVTdNV3beq762qz+ucPnXvrVtVH7YPd6n7u+acQ0REuicn6AAiIulMJSoi4oNKVETEB5WoiIgPKlERER9UoiIiPqSkRM3sC2a2zcx2mNkDqfgMEZEwsGR/T9TMcoEPgNlANbAG+IZzbnNSP0hEJARSsSV6GbDDOfeRc64ReB64MQWfIyISuF4peM9SoCpmvhq4vLMXDBkyxJWVlaUgiohI1+3cuZMDBw5YIuumokQ7+uAzjhmY2TxgHsDo0aOprKxMQRQRka4rLy9PeN1U7M5XA6Ni5kcCu9uv5Jyb75wrd86Vl5SUpCCGiEjqpaJE1wATzGysmeUDtwILU/A5IiKBS/ruvHPulJn9LbAYyAWeds5tSvbniIiEQSqOieKcew14LRXvLSISJrpiSUTEB5WoiIgPKlERER9UoiIiPqhERUR8UImKiPigEhUR8UElKiLig0pURMQHlaiIiA8qURERH1SiIiI+qERFRHxQiYqI+KASFRHxQSUqIuKDSlRExAeVqIiIDypREREfVKIiIj6oREVEfFCJioj4oBIVEfFBJSoi4oNKVETEB5WoiIgPKlERER9UoiIiPqhERUR8UImKiPigEhUR8UElKiLig0pURMSHuCVqZk+b2X4z2xizbJCZLTGz7d7jQG+5mdmvz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c/d++wpQKX3Z/97YGAYcybjR1csiYj4EPTuvIhIWlOJioj4oBIVEfFBJSoi4oNKVETEB5WoiIgPKlERER9UoiIiPvx/nQJTgNT2nFMAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "原始图像形状: (516, 696)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAD8CAYAAAC4nHJkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvIxREBQAADf1JREFUeJzt3V2IHed9x/HfTy8r9GZbttaKkGQrFrKpMVgpi6hxKS5BwSkBOxcx0UVQIUS5iKGBXNToJr4pmNIk9UUJKLWIDImTQOJaGNPGmIIbKMFrY2TLShu/bCVZa2llxYqDX1ar/fdiR2Ej75k5OnPmzNn9fz8g9px5Zs78Pfh35pzzzDyPI0IA8lnWdgEA2kH4gaQIP5AU4QeSIvxAUoQfSIrwA0kRfiApwg8ktWKQO9u4cWNs3759kLsEUpmYmNC5c+fczbq1wm/7XkmPSlou6V8j4pGy9bdv367x8fE6uwRQYmxsrOt1e/7Yb3u5pH+R9HlJt0vaa/v2Xl8PwGDV+c6/W9LrEfFmRExL+omk+/pTFoCm1Qn/Fkkn5z0/VSz7E7b32x63PT41NVVjdwD6qU74F/pR4RP3B0fEwYgYi4ix0dHRGrsD0E91wn9K0rZ5z7dKOl2vHACDUif8L0jaafvTtkckfVnSkf6UBaBpPXf1RcSM7Qcl/YfmuvoORcSxvlUGoFG1+vkj4hlJz/SpFgADxOW9QFKEH0iK8ANJEX4gKcIPJEX4gaQIP5AU4QeSIvxAUoQfSIrwA0kRfiApwg8kR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OiK7Gyxto+D+xc3s8IsZaK6DEsNY2rHVJ1NartmrjYz+QFOEHkmo7/Adb3n+ZYa1tWOuSqK1XrdTW6nd+AO1p+8wPoCWthN/2vbb/x/brth9qo4ZObE/YfsX2y7bHW67lkO2ztl+dt+x628/a/m3xd8Fp0lqq7WHbbxfH7mXbf9NSbdts/6ft47aP2f67Ynmrx66krlaO28A/9tteLul/Je2RdErSC5L2RsRrAy2kA9sTksYiovU+Ydt/JekPkh6PiDuKZf8o6XxEPFK8cW6IiL8fktoelvSHtmduLiaU2Tx/ZmlJ90v6W7V47ErqekAtHLc2zvy7Jb0eEW9GxLSkn0i6r4U6hl5EPC/p/BWL75N0uHh8WHP/8wxch9qGQkRMRsRLxeP3JV2eWbrVY1dSVyvaCP8WSSfnPT+l4ZryOyT90vaLtve3XcwCNhXTpl+ePv3Gluu5UuXMzYN0xczSQ3Psepnxut/aCP9CYysNU5fD3RHx55I+L+kbxcdbdKermZsHZYGZpYdCrzNe91sb4T8ladu851slnW6hjgVFxOni71lJT2r4Zh8+c3mS1OLv2Zbr+aNhmrl5oZmlNQTHbphmvG4j/C9I2mn707ZHJH1Z0pEW6vgE22uLH2Jke62kz2n4Zh8+Imlf8XifpKdarOVPDMvMzZ1mllbLx27YZrxu5SKfoivjnyUtl3QoIv5h4EUswPYtmjvbS3MjG/+4zdpsPyHpHs3d9XVG0rcl/Zukn0m6SdIJSV+KiIH/8Nahtns099H1jzM3X/6OPeDa/lLSf0l6RdJssfiA5r5ft3bsSuraqxaOG1f4AUlxhR+QFOEHkiL8QFKEH0iK8ANJEX4gKcIPJEX4gaT+H6AIGgLsC7P0AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "采样后图像形状: (28, 28)\n"
     ]
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "from PIL import Image\n",
    "img_path='310.png'\n",
    "im=Image.open(img_path)\n",
    "plt.imshow(im)\n",
    "plt.show()\n",
    "im=im.convert('L')\n",
    "print('原始图像形状:',np.array(im).shape)\n",
    "im=im.resize((28,28),Image.ANTIALIAS)\n",
    "plt.imshow(im)\n",
    "plt.show()\n",
    "print(\"采样后图像形状:\",np.array(im).shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the number is: 5\n"
     ]
    }
   ],
   "source": [
    "def load_iamge(img_path):\n",
    "    im=Image.open(img_path).convert('L')\n",
    "    im=im.resize((28,28),Image.ANTIALIAS)\n",
    "    im=np.array(im).reshape(1,-1).astype(np.float32)\n",
    "    im=1-im/255\n",
    "    return im\n",
    "model=MNIST()\n",
    "params_file_path='./mnist.pdparams'\n",
    "param_dict=paddle.load(params_file_path)\n",
    "model.load_dict(param_dict)\n",
    "\n",
    "model.eval()\n",
    "tensor_img=load_iamge(img_path)\n",
    "result=model(paddle.to_tensor(tensor_img))\n",
    "print('the number is:',np.argsort(result.numpy())[0][-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
